export const loop = async (
  nodes: any[],
  limit: number = 1,
  callback: (data: any) => Promise<any>,
) => {
  if (nodes?.length > 0) {
    const range = nodes?.splice(0, limit);
    const promises = range?.map(async (data) => {
      return await callback?.(data).catch(() => Promise.resolve());
    });
    await Promise.all(promises).then(() => loop(nodes, limit, callback));
  }
  return Promise.resolve();
};
